package nongchang.kuaijiecaifu.com.ncapp_android.util;

import android.content.Context;

/**
 * Created by Administrator on 2016/3/10 0010.
 */
public class ScaleUtil {

    public static int dip2px(Context context,float dipValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    /**
     * px转成dp
     * @param pxValue
     * @return
     */
    public static int px2dip(Context context,float pxValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * sp转成px
     * @param spValue
     * @param type
     * @return
     */
    public static float sp2px(Context context,float spValue, int type) {
        float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
        switch (type) {
            case 1:
                return spValue * scaledDensity;
            case 2:
                return spValue * scaledDensity * 10.0f / 18.0f;
            default:
                return spValue * scaledDensity;
        }
    }
}
